package com.weishi.project.api.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.weishi.common.utils.StringUtils;
import com.weishi.common.utils.file.FileUploadUtils;
import com.weishi.framework.aspectj.lang.annotation.Log;
import com.weishi.framework.aspectj.lang.enums.BusinessType;
import com.weishi.framework.config.RuoYiConfig;
import com.weishi.framework.web.controller.BaseController;
import com.weishi.framework.web.domain.AjaxResult;
import com.weishi.framework.web.page.TableDataInfo;
import com.weishi.project.api.vo.*;
import com.weishi.project.sport.movement.service.MovementService;
import com.weishi.project.system.domain.SysUser;
import com.weishi.project.training.domain.*;
import com.weishi.project.training.service.*;
import io.lettuce.core.dynamic.annotation.Param;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/app/sportsman")
@Api(value = "Sportsman", description = "运动员-界面")
public class ApiSportsmanController extends BaseController {

    @Autowired
    private ISportsmanService sportsmanService;

    @Autowired
    private ILeaveFormService leaveFormService;

    @Autowired
    private ITrainingAchievementService achievementService;

    @Autowired
    private ISportsmanPhysicalQualityService sportsmanPhysicalQualityService;

    @Autowired
    private ISportsmanMatchService sportsmanMatchService;

    @Autowired
    private ISportsmanBodyFunctionService sportsmanBodyFunctionService;

    @Autowired
    private ITrainingDayService trainingDayService;

    @Autowired
    private ITrainingWeekService trainingWeekService;

    /**
     * 身体形态接口
     */
    @Autowired
    private ISportsmanBodyShapeService sportsmanBodyShapeService;

    /**
     * 运动模块接口
     */
    @Autowired
    private MovementService movementService;


    @ApiOperation(value = "分页查询运动员", response = Sportsman.class)
    @PostMapping("/listByPage")
    public TableDataInfo listByPage(@RequestBody Sportsman sportsman) throws Exception {
        startPage();
        List<Sportsman> list = sportsmanService.selectSportsmanList(sportsman);
        return getDataTable(list);
    }

    @ApiOperation(value = "查询运动员", response = Sportsman.class)
    @PostMapping("/list")
    public AjaxResult list(@RequestBody Sportsman sportsman) throws Exception {
        List<Sportsman> list = sportsmanService.selectSportsmanList(sportsman);

        // 把缺少的值，赋值
        list.forEach( p->{
            List<SportsmanBodyShape> sportsmanBodyShapeList = sportsmanBodyShapeService
                    .list(Wrappers.<SportsmanBodyShape>lambdaQuery()
                            .eq(SportsmanBodyShape::getSportsmanId , p.getId())
                            .orderByDesc(SportsmanBodyShape::getCtime));
            if(sportsmanBodyShapeList.size() > 0){
                p.setHeight(sportsmanBodyShapeList.get(0).getHeight());
                p.setSitHigh(sportsmanBodyShapeList.get(0).getSitHigh());
                p.setArmSpread(sportsmanBodyShapeList.get(0).getArmSpread());
                p.setShoulderWidth(sportsmanBodyShapeList.get(0).getShoulderWidth());
                p.setLegLength(sportsmanBodyShapeList.get(0).getLegLength());
                p.setTinyLegLength(sportsmanBodyShapeList.get(0).getTinyLegLength());
                p.setBust(sportsmanBodyShapeList.get(0).getBust());
                p.setHipline(sportsmanBodyShapeList.get(0).getHipline());
                p.setWaistline(sportsmanBodyShapeList.get(0).getWaistline());
            }

        });

        return AjaxResult.success(list);
    }

    @ApiOperation(value = "获取运动员详细信息")
    @GetMapping("/getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(sportsmanService.getById(id));
    }

    @ApiOperation(value = "新增运动员")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Sportsman sportsman) {
        sportsman.setStatus("0");
        sportsman.setCtime(new Date());
        sportsman.setLtime(new Date());
        sportsmanService.save(sportsman);
        return AjaxResult.success(sportsman);
    }

    @ApiOperation(value = "新增运动员and物理属性")
    @PostMapping("/addAll")
    public AjaxResult addAll(@RequestBody SportsmanAllVo sportsman) {
        sportsmanService.saveAll(sportsman);
        return AjaxResult.success();
    }

    @ApiOperation(value = "修改运动员")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody SportsmanAllVo sportsman) {
        Sportsman temp = sportsman.getSportsman();
        temp.setLtime(new Date());
        sportsmanService.updateById(temp);

        /**
         * 新增一条身体形态
         */
        SportsmanBodyShape sportsmanBodyShape = new SportsmanBodyShape();
        StringUtils.copyProperties(temp , sportsmanBodyShape);
        sportsmanBodyShape.setSportsmanId(Long.parseLong(temp.getId().toString()));
        sportsmanBodyShape.setCtime(new Date());
        sportsmanBodyShapeService.save(sportsmanBodyShape);
        return AjaxResult.success();
    }

    @ApiOperation(value = "获取运动员物理属性(身体素质)详细信息-最新")
    @GetMapping("/getSportsmanPhysicalQualityInfo")
    public AjaxResult getSportsmanPhysicalQualityInfo(@RequestParam("sportsmanId") Integer sportsmanId) {
        return AjaxResult.success(sportsmanPhysicalQualityService.getSportsmanPhysicalQualityBySportsmanId(sportsmanId, false));
    }

//    @ApiOperation(value = "获取运动员物理属性(身体素质)详情")
//    @GetMapping("/getSportsmanPhysicalQualityDetails")
//    public AjaxResult getSportsmanPhysicalQualityDetails(@RequestParam("sportsmanId") Integer sportsmanId) {
//        return AjaxResult.success(sportsmanPhysicalQualityService.getSportsmanPhysicalQualityById(sportsmanId));
//    }

    @ApiOperation(value = "获取运动员物理属性(身体素质)信息-最优")
    @GetMapping("/getOptimalSportsmanPhysicalQualityInfo")
    public AjaxResult getOptimalSportsmanPhysicalQualityInfo(@RequestParam("sportsmanId") Integer sportsmanId) {
        return AjaxResult.success(sportsmanPhysicalQualityService.getSportsmanPhysicalQualityBySportsmanId(sportsmanId, true));
    }

    /**
     * 查询运动员物理属性列表
     */
//    @ApiOperation(value = "查询运动员物理属性(身体素质)")
//    @GetMapping("/sportsmanPhysicalQualityList")
//    public AjaxResult list(@ApiParam(name = "sportManId", value = "运动员Id") @RequestParam("sportManId") Integer sportManId) {
//        SportsmanPhysicalQuality sportsmanPhysicalQuality = new SportsmanPhysicalQuality();
//        sportsmanPhysicalQuality.setSportsmanId(sportManId);
//        Map<String,List<SportsmanPhysicalQualityRet>> map = sportsmanPhysicalQualityService.selectMapList(sportsmanPhysicalQuality);
//        return AjaxResult.success(map);
//    }
    @ApiOperation(value = "新增运动员物理属性(身体素质)")
    @PostMapping("/addSportsmanPhysicalQuality")
    public AjaxResult addSportsmanPhysicalQuality(@RequestBody SportsmanPhysicalQuality sportsmanPhysicalQuality) {
        sportsmanPhysicalQualityService.save(sportsmanPhysicalQuality);
        return AjaxResult.success();
    }

    @ApiOperation(value = "修改运动员物理属性(身体素质)")
    @PostMapping("/editSportsmanPhysicalQuality")
    public AjaxResult editSportsmanPhysicalQuality(@RequestBody SportsmanPhysicalQuality sportsmanPhysicalQuality) {
        SportsmanPhysicalQualityVo sportsmanPhysicalQualityVo = sportsmanPhysicalQuality.getSportsmanPhysicalQuality();
        SportsmanPhysicalQuality sportsmanPhysicalQuality1 = sportsmanPhysicalQualityVo.getSportsmanPhysicalQuality();
        sportsmanPhysicalQualityService.updateSportsmanPhysicalQualityById(sportsmanPhysicalQuality1);
        return AjaxResult.success();
    }

    /**
     * 删除运动员物理属性
     */
    @ApiOperation(value = "删除运动员物理属性(身体素质)")
    @GetMapping("/removeSportsmanPhysicalQuality/{ids}")
    public AjaxResult removeSportsmanPhysicalQuality(@PathVariable Integer[] ids) {
        sportsmanPhysicalQualityService.removeByIds(Arrays.asList(ids));
        return AjaxResult.success();
    }

    @ApiOperation(value = "删除运动员")
    @GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        sportsmanService.removeByIds(Arrays.asList(ids));
        return AjaxResult.success();
    }

    //不同项目不同艇支不同公里数下前n次的成绩按降序排序
    @ApiOperation(value = "专项最好成绩")
    @PostMapping("/bestResultSpecialProject")
    public AjaxResult bestResultSpecialProject(@RequestBody SportManBestResultVo sportManBestResultVo) {
       /* if (sportManBestResultVo.getTimes() == 0) {
            sportManBestResultVo.setTimes(3);
        }*/
        return AjaxResult.success(sportsmanService.getBestResultSpecialProject(sportManBestResultVo));
    }

    @ApiOperation(value = "最佳搭档-最好成绩")
    @GetMapping("/partnerCooperationResult")
    public AjaxResult bestPartnerByResult(@ApiParam(name = "sportsManId", value = "运动员Id") @RequestParam("sportsManId") Integer sportsManId,
                                          @ApiParam(name = "kilometers", value = "公里数") @Param("kilometers") Integer kilometers,
                                          @ApiParam(name = "boatType", value = "艇支类型") @Param("boatType") String boatType) {
        //某个项目某个艇支某个公里数我所取得的最好成绩时的搭档是那些
        List<BestPartnerResultVo> bestPartnerResultVos = sportsmanService.getBestList(sportsManId, kilometers, boatType);
        List<Map<String, Object>> list = new ArrayList<>();
        for (int i = 0; i < bestPartnerResultVos.size(); i++) {
            if (bestPartnerResultVos.get(i).getBoatType()==null || bestPartnerResultVos.get(i).getBoatType().equals("M 1X") || bestPartnerResultVos.get(i).getBoatType().equals("W 1X")) {
                bestPartnerResultVos.remove(bestPartnerResultVos.get(i));
                i--;
            } else {
                Map<String, Object> temp = new HashMap<>();
                temp.put("achievementId", bestPartnerResultVos.get(i).getAchievementId());
                temp.put("boatType", bestPartnerResultVos.get(i).getBoatType());
                temp.put("kilometers", bestPartnerResultVos.get(i).getKilometers());
                temp.put("achievement", bestPartnerResultVos.get(i).getAchievement());
                List<TrainingAchievementMaxVo> listz = achievementService.selectTrainingAchievementListByChannelId(bestPartnerResultVos.get(i).getChannelId());
                for (int j = 0; j < listz.size(); j++) {
                    if (listz.get(j).getSportsmanId().equals(sportsManId)) {
                        listz.remove(listz.get(j));
                        j--;
                    }
                }
                temp.put("sportsMans", listz);
                list.add(temp);
            }
        }
        return AjaxResult.success(list);
    }


    @ApiOperation(value = "最佳搭档-合作次数")
    @GetMapping("/partnerCooperationTimes")
    public AjaxResult bestPartnerByTimes(@ApiParam(name = "sportsManId", value = "运动员Id") @RequestParam("sportsManId") Integer sportsManId) {
        List<BestPartnerCountVo> bestPartnerCountVos = sportsmanService.getBestPartnerCountVoList(sportsManId);

        for (int i = 0; i < bestPartnerCountVos.size(); i++) {
            bestPartnerCountVos.get(i).setName(sportsmanService.getNameById(bestPartnerCountVos.get(i).getSportsManId()));
            if (bestPartnerCountVos.get(i).getBoatType()==null || bestPartnerCountVos.get(i).getBoatType().equals("M 1X") || bestPartnerCountVos.get(i).getBoatType().equals("W 1X")) {
                bestPartnerCountVos.remove(bestPartnerCountVos.get(i));
                i--;
            }
        }
        Map<Integer, List<BestPartnerCountVo>> map = bestPartnerCountVos.stream().collect(Collectors.toMap(BestPartnerCountVo::getSportsManId,
                p -> {
                    List<BestPartnerCountVo> itemList = new ArrayList<>();
                    itemList.add(p);
                    return itemList;
                },
                (List<BestPartnerCountVo> value1, List<BestPartnerCountVo> value2) -> {
                    value1.addAll(value2);
                    return value1;
                }
        ));

        List<BestPartnerCountReturnVo> list2 = new ArrayList<>();
        for (Map.Entry<Integer, List<BestPartnerCountVo>> entry : map.entrySet()) {
            BestPartnerCountReturnVo bestPartnerCountReturnVo = new BestPartnerCountReturnVo();
            if (!entry.getKey().equals(sportsManId)) {
                bestPartnerCountReturnVo.setSportsManId(entry.getKey());
                bestPartnerCountReturnVo.setListVos(entry.getValue());
                list2.add(bestPartnerCountReturnVo);
            }
        }
        return AjaxResult.success(list2);
    }

    @ApiOperation(value = "周与周训练量/(时长)对比")
    @GetMapping("/weekTrainingCompletion")
    public AjaxResult weekTrainingCompletion(WeekTrainingCompletionVo weekTrainingCompletionVo) {
        List<Map<String, Object>> list = trainingDayService.selectWeekTrainingData(weekTrainingCompletionVo);
        return AjaxResult.success(list);
    }

    @ApiOperation(value = "周与周个训练项目训练成绩对比")
    @GetMapping("/weekTrainingAchievementCompletion")
    public AjaxResult weekTrainingAchievementCompletion(WeekTrainingCompletionVo weekTrainingCompletionVo) {
        List<Map<String, Object>> list = trainingDayService.weekTrainingAchievementCompletion(weekTrainingCompletionVo);
        return AjaxResult.success(list);
    }

    @ApiOperation(value = "水上专项提升与下降数据分析")
    @PostMapping("/waterSpecialPromotion")
    public AjaxResult waterSpecialPromotion(@RequestBody WaterSpecialPromotionVo waterSpecialPromotionVo) {
        List<Map<String, Object>> list = trainingDayService.waterSpecialPromotion(waterSpecialPromotionVo);
        return AjaxResult.success(list);
    }

    @ApiOperation(value = "不同艇支完成次数")
    @PostMapping("/boatFrequency")
    public AjaxResult boatFrequency(@RequestBody BoatFrequencyVo boatFrequencyVo) {
        //根据不同运动员查询在不同艇支完成次数
        return AjaxResult.success(sportsmanService.getCountBoatFrequency(boatFrequencyVo));
    }

    @ApiOperation(value = "号位占比")
    @PostMapping("/positionRatio")
    public AjaxResult positionRatio(@RequestBody PositionRatioVo positionRatioVo) {
        List<Map<String, Object>> list = sportsmanService.getCountPositionRatio(positionRatioVo);
        for (Map<String, Object> map : list) {
            if (map.get("boatType").equals("M 1X") || map.get("boatType").equals("W 1X")) {
                list.remove(map);
            }
        }
        return AjaxResult.success(sportsmanService.getCountPositionRatio(positionRatioVo));
    }

    @ApiOperation(value = "身体机能分析")
    @GetMapping("/bodyFunctionAnalysis")
    public AjaxResult bodyFunction(@ApiParam(name = "sportsManId", value = "运动员Id") @RequestParam("sportsManId") Integer sportsManId) {
        List<BodyFunctionAnalysisVo> list = sportsmanService.getBodyFunctionAnalysisVoByweek(sportsManId);
        /*List<Map<String,Object>> retList = new ArrayList<>();
        for(BodyFunctionAnalysisVo sportsmanBodyFunction : list){
            Map<String,Object> map = new HashMap<>();
            map.put("bodyFunction",BodyFunctionAnalysisVo.getMap(sportsmanBodyFunction));
            retList.add(map);
        }*/
        // 判断 list 是否只有一条数据，如果只有一条，那么就追加一个对象
        if(list.size() == 1){
            BodyFunctionAnalysisVo bodyFunctionAnalysisVo = new BodyFunctionAnalysisVo();
            bodyFunctionAnalysisVo.setBla(0.0);
            bodyFunctionAnalysisVo.setBu(0.0);
            bodyFunctionAnalysisVo.setCk(0.0);
            bodyFunctionAnalysisVo.setHb(0.0);
            bodyFunctionAnalysisVo.setHbp(0.0);
            bodyFunctionAnalysisVo.setHr(0.0);
            bodyFunctionAnalysisVo.setLbp(0.0);
            bodyFunctionAnalysisVo.setSt(0.0);
            bodyFunctionAnalysisVo.setUa(0.0);
            bodyFunctionAnalysisVo.setWeight(0.0);
            list.add(bodyFunctionAnalysisVo);
        }

        return AjaxResult.success(list);
    }

    @ApiOperation(value = "身体机能数据图")
    @GetMapping("/bodyFunctionChart")
    public AjaxResult bodyFunctionChart(Integer sportsManId) {
        LambdaQueryWrapper<SportsmanBodyFunction> queryWrapper = Wrappers.<SportsmanBodyFunction>lambdaQuery();
        queryWrapper.eq(SportsmanBodyFunction::getSportsmanId, sportsManId);
        List<SportsmanBodyFunction> list = sportsmanBodyFunctionService.getSoprtBodyFunctionAnalysisVoByweek(sportsManId);

        List<Map<String, Object>> retList = new ArrayList<>();
        for (SportsmanBodyFunction sportsmanBodyFunction : list) {
            Map<String, Object> map = new HashMap<>();
            if(sportsmanBodyFunction.getCollectionTime()!=null){
                map.put("day", sportsmanBodyFunction.getCollectionTime());
            }else{
                map.put("day", sportsmanBodyFunction.getCtime());
            }
            map.put("bodyFunction", SportsmanBodyFunction.getMapTo(sportsmanBodyFunction));
            retList.add(map);
        }
        return AjaxResult.success(retList);
    }


    @ApiOperation(value = "身体素质排名")
    @PostMapping("/ranking")
    public AjaxResult ranking(@RequestBody Map<String, List<RangkingDetailsParamsVo>> params) {
        List<RangkingDetailsParamsVo> rankingParamsVos = params.get("rankingParamsVos");
        return AjaxResult.success(sportsmanPhysicalQualityService.getRanking(rankingParamsVos));
    }

    @ApiOperation(value = "身体素质查看历史")
    @PostMapping("/getHistory")
    public AjaxResult getHistory(@RequestBody HistoryVo historyVo) {
        return AjaxResult.success(sportsmanPhysicalQualityService.getSportsmanPhysicalQualityHistory(historyVo));
    }

    @ApiOperation(value = "身体素质排名详情")
    @PostMapping("/getRankingDetails")
    public AjaxResult getRankingDetails(@RequestBody RangkingDetailsParamsVo rangkingDetailsParamsVo) {
        return AjaxResult.success(sportsmanPhysicalQualityService.getRangkingDetailsVo(rangkingDetailsParamsVo));
    }


    @ApiOperation(value = "身体素质数据图")
    @GetMapping("/bodyChart")
    public AjaxResult bodyChart(Integer sportsManId) {
        LambdaQueryWrapper<SportsmanPhysicalQuality> queryWrapper = Wrappers.<SportsmanPhysicalQuality>lambdaQuery();
        queryWrapper.eq(SportsmanPhysicalQuality::getSportsmanId, sportsManId);
        List<SportsmanPhysicalQuality> list = sportsmanPhysicalQualityService.list(queryWrapper);
        List<Map<String, Object>> retList = new ArrayList<>();
        for (SportsmanPhysicalQuality sportsmanPhysicalQuality : list) {
            Map<String, Object> map = new HashMap<>();
            map.put("bodyFunction", SportsmanPhysicalQuality.getMap(sportsmanPhysicalQuality));
            retList.add(map);
        }
        return AjaxResult.success(retList);
    }

    @ApiOperation(value = "身体机能数据列表")
    @GetMapping("/bodyFunctionTable")
    public AjaxResult bodyFunctionTable(Integer sportsManId) {
        LambdaQueryWrapper<SportsmanBodyFunction> queryWrapper = Wrappers.<SportsmanBodyFunction>lambdaQuery();
        queryWrapper.eq(SportsmanBodyFunction::getSportsmanId, sportsManId);
        List<SportsmanBodyFunction> list = sportsmanBodyFunctionService.list(queryWrapper);
        List<Map<String, Object>> retList = new ArrayList<>();

        for (SportsmanBodyFunction sportsmanBodyFunction : list) {
            Map<String, Object> map = new HashMap<>();
            if(sportsmanBodyFunction.getCollectionTime()!=null){
                map.put("day", sportsmanBodyFunction.getCollectionTime());
            }else{
                map.put("day", sportsmanBodyFunction.getCtime());
            }
            map.put("bodyFunction", SportsmanBodyFunction.getMap(sportsmanBodyFunction));
            retList.add(map);
        }
        Collections.sort(retList, new Comparator<Map<String, Object>>() {
            @Override
            public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                return o1.get("day").toString().compareTo(o2.get("day").toString());
            }
        });
        return AjaxResult.success(retList);
    }

    @ApiOperation(value = "受伤次数统计")
    @GetMapping("/injuryCount")
    public AjaxResult injuryCount(@ApiParam(name = "sportsManId", value = "运动员id") @RequestParam("sportsManId") String sportsManId) {
        //传受伤类型和受伤部位统计受伤部位对应次数
        Map<String, Object> map = new HashMap<>();
        map.put("sportsManId", sportsManId);
        return AjaxResult.success(sportsmanService.injuryCount(map));
    }

    @ApiOperation(value = "受伤部位修复时间")
    @GetMapping("/injuryHoursCount")
    public AjaxResult injuryHoursCount(@ApiParam(name = "sportsManId", value = "运动员id") @RequestParam("sportsManId") String sportsManId) {
        //传受伤类型和受伤部位统计受伤部位对应次数
        Map<String, Object> map = new HashMap<>();
        map.put("sportsManId", sportsManId);
        return AjaxResult.success(sportsmanService.injuryHoursCount(map));
    }

    @ApiOperation(value = "受伤史")
    @GetMapping("/injuryList")
    public AjaxResult injuryList(@ApiParam(name = "sportsManId", value = "运动员id") @RequestParam("sportsManId") String sportsManId,
                                 @ApiParam(name = "startTime", value = "开始时间") @RequestParam("startTime") String startTime,
                                 @ApiParam(name = "endTime", value = "结束时间") @RequestParam("endTime") String endTime) {
        //传受伤类型和受伤部位统计受伤部位对应次数
        Map<String, Object> map = new HashMap<>();
        map.put("startTime", startTime);
        map.put("endTime", endTime);
        map.put("sportsManId", sportsManId);
        return AjaxResult.success(leaveFormService.queryBySportsmanIdAll(map));
    }

    @ApiOperation(value = "生病史")
    @GetMapping("/illnessList")
    public AjaxResult illnessList(@ApiParam(name = "sportsManId", value = "运动员id") @RequestParam("sportsManId") String sportsManId,
                                  @ApiParam(name = "startTime", value = "开始时间") @RequestParam("startTime") String startTime,
                                  @ApiParam(name = "endTime", value = "结束时间") @RequestParam("endTime") String endTime) {
        //传受伤类型和受伤部位统计受伤部位对应次数
        Map<String, Object> map = new HashMap<>();
        map.put("startTime", startTime);
        map.put("endTime", endTime);
        map.put("sportsManId", sportsManId);
        return AjaxResult.success(leaveFormService.queryBySportsmanllness(map));
    }

    @ApiOperation(value = "过敏史")
    @GetMapping("/allergyList")
    public AjaxResult allergyList(@ApiParam(name = "sportsManId", value = "运动员id") @RequestParam("sportsManId") String sportsManId,
                                  @ApiParam(name = "startTime", value = "开始时间") @RequestParam("startTime") String startTime,
                                  @ApiParam(name = "endTime", value = "结束时间") @RequestParam("endTime") String endTime) {
        //传受伤类型和受伤部位统计受伤部位对应次数
        Map<String, Object> map = new HashMap<>();
        map.put("startTime", startTime);
        map.put("endTime", endTime);
        map.put("sportsManId", sportsManId);
        return AjaxResult.success(leaveFormService.queryBySportsmanAllergy(map));
    }

    @ApiOperation(value = "不同艇支划行训练量(公里数)")
    @GetMapping("/trainingBoatType")
    public AjaxResult trainingBoatType(@ApiParam(name = "sportsManId", value = "运动员Id") @RequestParam("sportsManId") Integer sportsManId) {
        return AjaxResult.success(sportsmanService.getCountTrainingBoatType(sportsManId));
    }


    @ApiOperation(value = "不同艇支划行时长")
    @GetMapping("/classHourBoatType")
    public AjaxResult classHourBoatType(@ApiParam(name = "sportsManId", value = "运动员Id") @RequestParam("sportsManId") Integer sportsManId) {
        List<Map<String, Object>> list = this.achievementService.selectClassHourBoatType(sportsManId);
        return AjaxResult.success(list);
    }

    @ApiOperation(value = "比赛成绩列表")
    @GetMapping("/resultsList")
    public TableDataInfo resultsList(@ApiParam(name = "sportsManId", value = "运动员Id") @RequestParam("sportsManId") Integer sportsManId) {
        SportsmanMatch sportsmanMatch = new SportsmanMatch();
        sportsmanMatch.setSportsmanId(sportsManId);
        startPage();
        List<SportsmanMatch> list = sportsmanMatchService.selectSportsmanMatchList(sportsmanMatch);
        return getDataTable(list);
    }

    /**
     * 新增sportsmanMatch
     */
    @ApiOperation(value = "比赛成绩新增或修改")
    @PostMapping("/addSportsmanMatch")
    public AjaxResult add(@RequestBody SportsmanMatch sportsmanMatch) {
        sportsmanMatch.setCtime(new Date());
        sportsmanMatchService.saveOrUpdate(sportsmanMatch);
        return AjaxResult.success(sportsmanMatch);
    }

    /**
     * 修改sportsmanMatch
     */
    @ApiOperation(value = "比赛成绩修改")
    @GetMapping("/updateSportsmanMatch")
    public AjaxResult edit(@RequestBody SportsmanMatch sportsmanMatch) {
        sportsmanMatchService.updateSportsmanMatchById(sportsmanMatch);
        return AjaxResult.success();
    }

    /**
     * 删除sportsmanMatch
     */
    @ApiOperation(value = "比赛成绩删除")
    @GetMapping("/deleteSportsmanMatch")
    public AjaxResult remove(@ApiParam(name = "id", value = "比赛成绩id") @RequestParam("id") Integer id) {
        sportsmanMatchService.removeById(id);
        return AjaxResult.success();
    }

    /**
     * 头像上传
     */
    @Log(title = "运动员头像", businessType = BusinessType.UPDATE)
    @PostMapping("/sportsman/avatar")
    public AjaxResult avatarSportsman(@RequestParam("avatarfile") MultipartFile file) throws IOException {
        if (!file.isEmpty()) {
            String avatar = FileUploadUtils.upload(RuoYiConfig.getAvatarPath(), file);
            AjaxResult ajax = AjaxResult.success();
            ajax.put("imgUrl", avatar);
            return ajax;
        }
        return AjaxResult.error("上传图片异常，请联系管理员");
    }

    @ApiOperation(value = "桨位占比")
    @GetMapping("/oarType")
    public AjaxResult oarTypeList(@ApiParam(name = "sportsManId", value = "运动员Id") @RequestParam("sportsManId") Integer sportsManId) {
        List<OarTypeVo> list = sportsmanService.getCountPulpPosition(sportsManId);
        return AjaxResult.success(list);
    }

    @ApiOperation(value = "伤病报告")
    @GetMapping("/injuryDetails")
    public AjaxResult injuryDetails(@ApiParam(name = "id", value = "id") @RequestParam("id") Integer id) {
        return AjaxResult.success(leaveFormService.getById(id));
    }

    /**
     * 查询用户名称集合
     */
    @ApiOperation(value = "用户名称集合")
    @GetMapping("/getSysUerList")
    public AjaxResult list(SysUser sysUser) {
        List<SysUser> list = trainingWeekService.getSysUerList();
        return AjaxResult.success(list);
    }


    @ApiOperation("运动员端--运动模块-- 根据用户 id 查询测功仪数据")
    @RequestMapping(value = "getDynamometerList", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult getDynamometerList(Integer userId , Integer groupId , Integer trainingDayId) {
        return movementService.getDynamometerList(userId , groupId , trainingDayId);
    }





}
